#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int T,n,m,l,v,x,cnt,d[N];
bool fpast;
struct node{
    int di,vi,ai;
}a[N];
int f(int x){
    return x*x;
}
bool check(int s,int e){
    int l,r;
    bool f1=false,f2=false;
    l=1,r=m;
    while(l<=r){
        int mid=l+r>>1;
        if(d[mid]>=s){
            f1=true;
            break;
        }
        l=mid+1;
    }
    l=1,r=m;
    while(l<=r){
        int mid=l+r>>1;
        if(d[mid]<=e){
            f2=true;
            break;
        }
        r=mid-1;
    }
    if(f1&&f2) return true;
    return false;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d%d",&n,&m,&l,&v);
        cnt=0;
        fpast=true;
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&a[i].di,&a[i].vi,&a[i].ai);
            if(a[i].ai<0) fpast=false;
        }
        for(int i=1;i<=m;i++){
            scanf("%d",&d[i]);
        }
        for(int i=1;i<=n;i++){
            if(a[i].vi<=v&&a[i].ai<=0) continue;
            if(a[i].vi>v&&a[i].ai>=0){
                if(check(a[i].di,l)) cnt++;
                continue;
            }
            int lef=0,rig=l;
            while(lef<=rig){
                int mid=lef+rig>>1;
                if(a[i].ai>0){
                    int dr=f(v)-f(a[i].vi);
                    if(mid>a[i].di+dr/(a[i].ai*2)) rig=mid-1;
                    else lef=mid+1;
                }
                if(a[i].ai<0){
                    int dr=f(v)-f(a[i].vi);
                    if(mid>a[i].di+dr/(a[i].ai*2)) rig=mid-1;
                    else lef=mid+1;
                }
            }
            if(a[i].ai>0&&lef>=a[i].di&&lef<=l){
                if(check(lef,l)) cnt++;
                continue;
            }
            if(a[i].ai<0&&lef-1>=a[i].di&&lef-1<=l){
                if(check(a[i].di,lef-1)) cnt++;
                continue;
            }
        }
        printf("%d ",cnt);
        if(cnt==0||!fpast){
            printf("%d\n",m);
            continue;
        }
        if(fpast) printf("%d\n",m-1);
    }
    return 0;
}
